package com.relax.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 */
public class NioTest6 {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = new FileInputStream("a.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("d.txt");
        FileChannel inputStreamChannel = fileInputStream.getChannel();
        FileChannel outputStreamChannel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(2);
        while (true){
            buffer.clear();
            int read = inputStreamChannel.read(buffer);
            System.out.println(read);
            if (read == -1){
                break;
            }
            buffer.flip();
            outputStreamChannel.write(buffer);
        }
        fileInputStream.close();
        fileOutputStream.close();


    }
}
